<?php


namespace App\Http\Controllers\Saas;


use App\Contract\ContractStatus;
use App\Http\Controllers\Controller;
use App\Http\Resources\PaginationCollection;
use App\Model\Agent;
use App\Model\AgentAmountLog;
use App\Model\AgentCashLog;
use App\Model\AgentHasShop;
use App\Model\Contract;
use App\Model\ContractTenant;
use App\Model\CountryLog;
use App\Model\TjCountry;
use App\Model\House;
use App\Utils\Result;
use App\Utils\Token;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;

class CountryLogController extends Controller
{
    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function index(Request $request)
    {
        $query = CountryLog::query();
        $page = $request->input('page', 1);
        $pageSize = $request->input('pageSize', 10);
        $name = $request->input('name');
        $mobile = $request->input('mobile');
        $sn = $request->input('sn');
        $type = $request->input('type');
        $query->when($type, function($q) use ($type) {
            $q->where('type', $type);
        });
        $query->when($mobile, function($q) use ($mobile) {
            $q->where('phone', 'like', "%{$mobile}%");
        });
        $query->when($sn, function($q) use ($sn) {
            $q->where('sn', 'like', "%{$sn}%");
        });
        $query->when($name, function($q) use ($name) {
            $q->where('name', 'like', "%{$name}%");
        });
        $data = $query->latest()->paginate($pageSize, ['*'], 'page', $page);
        return Result::success(new PaginationCollection($data));
    }
}
